package com.jk.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.dao.TemCandidateMapper;
import com.jk.dto.CountRenshu;
import com.jk.dto.TemCandidate;
import com.jk.pojo.PagedResponse;
import com.jk.service.TemCandidateService;
import com.jk.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yzf
 * @version 1.0
 * @ClassName TemCandidateServiceImpl
 * @program: office
 * @description: TODO
 * @date 2025/2/17 14:13
 */
@Service
public class TemCandidateServiceImpl implements TemCandidateService {

    @Autowired
    private TemCandidateMapper temCandidateMapper;

    @Override
    public PagedResponse<TemCandidate> findTemCandidateList(TemCandidate temCandidate, Integer pageNum, Integer pageSize) {
        Page<TemCandidate> page  = new Page<>(pageNum, pageSize);
        IPage<TemCandidate> ipage = temCandidateMapper.findTemCandidateList(temCandidate,page);
        return PaginationUtil.getPaginationResponse(ipage.getRecords(),pageNum,pageSize, ipage.getTotal());
    }

    @Override
    public void addTemCandidate(TemCandidate temCandidate) {
        temCandidate.setIsdelete(0);
        temCandidateMapper.insert(temCandidate);
    }

    @Override
    public void updateTemCandidate(TemCandidate temCandidate) {
        temCandidateMapper.updateById(temCandidate);
    }

    @Override
    public TemCandidate getTemCandidateById(Integer id) {
        return temCandidateMapper.getTemCandidateById(id);
    }

    @Override
    public void updateStateById(Integer id,String process) {
        if (process.equals("初筛")){
            //变成待面试
            temCandidateMapper.updateOneById(id);
        }else if (process.equals("待面试")){
            //面试中
            temCandidateMapper.updateTwoById(id);
        }else if (process.equals("面试中")){
            //面试通过
            temCandidateMapper.updateThreeById(id);
        }else if (process.equals("面试通过")){
            //已发offer
            temCandidateMapper.updateFourById(id);
        }else if (process.equals("已发offer")){
            //待入职
            temCandidateMapper.updateFiveById(id);
        }else if (process.equals("待入职")){
            //假删
            temCandidateMapper.updateSixById(id);
        }else if (process.equals("人才库")){
            temCandidateMapper.updateTwoById(id);
        }
    }

    @Override
    public List<TemCandidate> findEchartsProcessList(TemCandidate temCandidate) {
        return temCandidateMapper.findEchartsProcessList(temCandidate);
    }

    @Override
    public List<CountRenshu> findCount() {
        List<CountRenshu> countRenshu = new ArrayList<>();
        //统计在招职位
        CountRenshu countRenshu1  = createCountRenshu(temCandidateMapper.getRecruitingPositions(), "在招职位", "el-icon-s-shop");
        countRenshu.add(countRenshu1);
        //统计未招满职位
        CountRenshu countRenshu2 = createCountRenshu(25, "未招满职位", "el-icon-document");
        countRenshu.add(countRenshu2);
        //计划招聘人数
        CountRenshu countRenshu3 = createCountRenshu(temCandidateMapper.getPlannedRecruitmentNumber(), "计划招聘人数", "el-icon-money");
        countRenshu.add(countRenshu3);
        //剩余招聘人数
        CountRenshu countRenshu4 = createCountRenshu(temCandidateMapper.getPlannedRecruitmentNumber() - temCandidateMapper.getYiruzhi(), "剩余招聘人数", "el-icon-truck");
        countRenshu.add(countRenshu4);
        //接收简历
        CountRenshu countRenshu5 = createCountRenshu(temCandidateMapper.getReceiveResumes(), "接收简历", "el-icon-s-shop");
        countRenshu.add(countRenshu5);
        //面试中
        CountRenshu countRenshu6 = createCountRenshu(temCandidateMapper.getInterviewing(), "面试中", "el-icon-document");
        countRenshu.add(countRenshu6);
//        //面试通过
         CountRenshu countRenshu7 = createCountRenshu(temCandidateMapper.getMianshitongguo(),"面试通过","el-icon-money");
         countRenshu.add(countRenshu7);
//        //待入职
        CountRenshu countRenshu8 = createCountRenshu(temCandidateMapper.getDairuzhi(),"待入职","el-icon-truck");
        countRenshu.add(countRenshu8);
//        //已入职
        CountRenshu countRenshu9 = createCountRenshu(temCandidateMapper.getYiruzhi(),"已入职","el-icon-user-solid");
        countRenshu.add(countRenshu9);
        return countRenshu;
    }
    // 辅助方法，用于创建JobStatistic实例
    private CountRenshu createCountRenshu(Integer value, String label, String icon) {
        CountRenshu count = new CountRenshu();
        count.setValue(value);
        count.setLabel(label);
        count.setIcon(icon);
        return count;
    }

    @Override
    public List<TemCandidate> findEchartsList() {
        return temCandidateMapper.findEchartsList();
    }

    @Override
    public Object findShuJvList() {
        Map<String, Object> params = new HashMap<>();
        //各部门入职人数
        List<Map<String, Object>> entryNum = temCandidateMapper.findShuJvList();
        params.put("entryNum", entryNum);
        //性别比例
        List<Map<String, Object>> sexNum = temCandidateMapper.findSexList();
        params.put("sexNum", sexNum);
        //学历分布
        List<Map<String, Object>> degreeNum = temCandidateMapper.findeducationalBackground();
        params.put("degreeNum", degreeNum);
//        //各部门招聘完成度
        //年龄分布
        List<Map<String, Object>> ageNum = temCandidateMapper.getAgeList();
        params.put("ageNum", ageNum);
        //招聘完成度
        List<Map<String, Object>> RuzhiNum = temCandidateMapper.getRuzhiList();
        params.put("RuzhiNum", RuzhiNum);
        //各部门招聘百分比
        List<Map<String, Object>> BaifenbiNum = temCandidateMapper.getBaifenbiList();
        params.put("BaifenbiNum", BaifenbiNum);


        return  params;
    }

}
